package com.lsfb.signsys.my;


import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.lsfb.signsys.BaseFragment;
import com.lsfb.signsys.R;
import com.lsfb.signsys.editpwd.EditPwdActivity;
import com.lsfb.signsys.utils.Utils;
import com.lsfb.signsys.view.BottomNavView.BageWrapper;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by zgscwjm on 2018/3/29.
 */

public class MyFragment extends BaseFragment implements MyContract.MyView {

    @BindView(R.id.fg_my_tv_name)
    TextView tv_username;

    @BindView(R.id.fg_my_tv_dep)
    TextView tv_depname;

    @BindView(R.id.fg_my_tv_job)
    TextView tv_jobname;

    @BindView(R.id.test)
    TextView tv_test;

    MyContract.Presenter mPresenter;


    @Override
    public int getContentView() {
        return R.layout.fragment_my;
    }

    @Override
    public void init() {
        new MyPresenter(this);
//        mPresenter = new MyPresenter(this);
//        mPresenter.subscribe();
    }


    @Override
    public void onResume() {
        super.onResume();
        mPresenter.subscribe();
    }

    @Override
    public void onStop() {
        super.onStop();
        mPresenter.unsubscribe();
    }


    @OnClick({R.id.fg_my_ln_feedback, R.id.fg_my_ln_clearcache,R.id.fg_my_ln_logout,R.id.fg_my_ln_edit,R.id.fg_my_ln_faceedit})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.fg_my_ln_feedback:
                mPresenter.feedback();
                break;
            case R.id.fg_my_ln_clearcache:

                String username = "放松放松的";
                Utils.getInstall().getInfoBean().subscribeOn(AndroidSchedulers.mainThread()).subscribe(b -> {
                    Toast.makeText(getActivity(), username+b.getUserName(), Toast.LENGTH_SHORT).show();
                });
                
                break;
            case R.id.fg_my_ln_logout:
                mPresenter.logout();
                break;

            case R.id.fg_my_ln_edit:
                mPresenter.editpwd();
                break;

            case R.id.fg_my_ln_faceedit:
                mPresenter.editfaceImg();
                break;
        }
    }

    @Override
    public void showEidtPwdActivity() {
        startActivity(new Intent(getContext(),EditPwdActivity.class));
    }

    @Override
    public void showFaceImgEditActivity() {
        BageWrapper.addBage(getContext(),tv_test);
    }

    @Override
    public void showPhoneEditActivity() {

    }

    @Override
    public void showFeedBackActivity() {

    }

    @Override
    public void updateMsgState(boolean enable) {

    }

    @Override
    public void updateCacheSize(int size) {

    }

    @Override
    public void showLoginActivity() {

    }

    @Override
    public void binderBaseInfo(String headImg, String userName, String jobsName) {
        tv_username.setText(userName);
        tv_jobname.setText(jobsName);

    }

    @Override
    public void setPresenter(MyContract.Presenter persenter) {
        mPresenter = persenter;
    }
}
